﻿#region Copyright Info

// 
// Majesty of Omega - The next evolution of macro management space strategy
// 
// Copyright 2007-2009 André Claaßen
// 
// This file is protected by the terms and conditions of the
// Microsoft Community License (Ms-CL 1.1), a copy of which should
// have been distributed along with this software. If not,
// you may find the license information at the following URL:
// 
// http://www.microsoft.com/resources/sharedsource/licensingbasics/communitylicense.mspx

#endregion

#region

using System.Windows;
using Majesty_of_Omega.GUI.Controller;
using Majesty_of_Omega.GUI.Pages.Parts;

#endregion

namespace Majesty_of_Omega.GUI.Pages.Game
{
    /// <summary>
    /// The SavePage.xaml is a Dialog for saving games. The animated Grid shows all save game entries.
    /// </summary>
    public partial class SavePage
    {
        /// <summary>
        /// The game play controller for this view
        /// </summary>
        private readonly GalaxyPageController _galaxyPageController;

        /// <summary>
        /// Initialize the page and set up the Routed Event Handlers.
        /// </summary>
        private void InitPage()
        {
            InitializeComponent();
            AddHandler(SaveGameEntryPart.LoadSaveGameEvent, new LoadSaveGameEventHandler(SavedGamesGrid_OnLoadSaveGame));
        }

        /// <summary>
        /// Initialize a new instance of  <see cref="SavePage"/> class. This Constructor is for test and design purposes
        /// </summary>
        public SavePage()
        {
            _galaxyPageController = GalaxyPageController.CreateDummyGamePlayController();
            InitPage();
        }

        /// <summary>
        /// Initialize a new instance of <see cref="SavePage"/> class.
        /// </summary>
        /// <param name="controller">The controller.</param>
        public SavePage(GalaxyPageController controller)
        {
            _galaxyPageController = controller;
            InitPage();
        }

        /// <summary>
        /// Handles the OnLoadSaveGame event of the SavedGamesGrid control. 
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private static void SavedGamesGrid_OnLoadSaveGame(object sender, LoadSaveGameEventArgs e)
        {
        }

        /// <summary>
        /// Handles the Click event of the Save Button.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void Save_Click(object sender, RoutedEventArgs e)
        {
            SaveGameBorder.Visibility = Visibility.Visible;
            _galaxyPageController.SaveCurrentGameAction();
            SaveGameBorder.Visibility = Visibility.Hidden;
            SavedGamesGrid.RefreshContent();
        }
    }
}